// 表格滚动到固定行
import Vue from 'vue';
const self = new Vue();
export const elTableScrollTorow = (dom, tableDataLen, showRow) => {
  let bodyWrapper = dom.$el.querySelector('.el-table__body-wrapper');
  if (tableDataLen > showRow) {
    self.$nextTick(() => {
      let tr = bodyWrapper.querySelectorAll('tr')[tableDataLen - 1];
      if (!bodyWrapper || !tr) {
        return;
      }
      bodyWrapper.scrollTo({
        top: tr.offsetTop,
        behavior: 'smooth'
      });
    });
  }
};

// crud行单选
export const rowClick = (dom, row, selectionList) => {
  // 选已选中数据中判断当前点击的是否被选中
  if (selectionList[0] == row) {
    // 选中的是已有的 取消选中
    selectionList = [];
    dom.toggleSelection();
    dom.setCurrentRow();
  } else {
    selectionList = [row];
    dom.toggleSelection();
    dom.toggleRowSelection(row, true);
  }
};
